< previous page page_506 next page >

Page 506
Keep your routines fairly short and easy to follow.
Indent all Loops and If statement code for easier reading.
If it is possible, use line numbers so that they can be displayed in the error-handling routines.
Name your forms, objects, and variables logically so that you can instantly know what they are or what they do.
The preceding suggestions will help you resolve many of the problems that can pop up. These are the syntax, compile, or runtime errors. However, the problems that you are really checking for when you test and debug the application are the logic errors in your code.
Logic errors are the toughest type of problem to find and fix because the error usually occurs further down the execution path in the application. For example, an incorrect result may be produced at the conclusion of a long series of calculation. In debugging, the task is to determine what and where something went wrong. It could be that you forgot to initialize a variable, chose the wrong operator or function, or used an incorrect formula. Making matters worse, logic problems are can be caused by bad data input, which means that a particular problem might not always happen.
Sometimes, these problems generate a runtime error that prevents the application from continuing. These bugs are usually found only by checking the results that the application returns against what the results should have been. This means that we have to perform the same functions and operations by hand that the application would do on the computer, enabling us to check the answers. This is known as desk-checking the application. This method got its name because programmers sat at their desks reading the application code and performing the actions of the application on paper. These days, supplied debugging tools have taken the place of the pencil and paper in the desk-checking process, although it should really still be done.
Unfortunately, there are no magic tricks in the debugging process, and there is no specific sequence of steps that will work every time you try them. Basically, debugging helps you to understand what is going on during the execution of the application. The Visual Basic-supplied debugging tools give you a snapshot of your application at any given moment in the process. The better you understand how your application works, the faster you can find the bugs.
The Debugging Environment
Visual Basic provides you with several very good tools for testing and debugging your application. These tools include breakpoint processing, Break expressions, Watch expressions, single-step processing, and the capability to display the contents of variables and

 
< previous page page_506 next page >

If you like this book, buy it!